/**
 * 
 */
package com.gcgt.server.trader;

import java.math.BigDecimal;

/**
 * @author Vincentas
 *
 */
public abstract class Position {

	private String ticker;
	
	private long amount;
	
	private BigDecimal price;

	/**
	 * @return the ticker
	 */
	public String getTicker() {
		return ticker;
	}

	/**
	 * @param ticker the ticker to set
	 */
	public void setTicker(String ticker) {
		this.ticker = ticker;
	}

	/**
	 * @return the amount
	 */
	public long getAmount() {
		return amount;
	}

	/**
	 * @param amount the amount to set
	 */
	public void setAmount(long amount) {
		this.amount = amount;
	}

	/**
	 * @return the price
	 */
	public BigDecimal getPrice() {
		return price;
	}

	/**
	 * @param price the price to set
	 */
	public void setPrice(BigDecimal price) {
		this.price = price;
	}	

	public BigDecimal getTotalPrice() {
		return getPrice().multiply(new BigDecimal(getAmount()));
	}

	public static Position createPosition(MarketUpdate update, BigDecimal cash) {
		long amount = cash.divideAndRemainder(update.getOpen())[0].longValue();
		
		Position result = null;
		result.setAmount(amount);
		result.setTicker(update.getTicker());
		result.setPrice(update.getOpen());
		
		return result;
	}
}
